package com.qf.controller;

import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.EurekaClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @author ASUS
 * @version V1.0
 * @Project SpringCloud
 * @Package com.qf.controller
 * @Date 2021/11/9 23:23
 */
@RestController
public class AirCoreController {

    @Autowired
    private RestTemplate restTemplate;

    @Resource
    private EurekaClient eurekaClient;
    
    @GetMapping("/air/core")
    public String core(){
        InstanceInfo instanceInfo = eurekaClient.getNextServerFromEureka("air-search", false);
        String ipAddr = instanceInfo.getIPAddr();
        int port = instanceInfo.getPort();
        String result = restTemplate.getForObject("http://"+ipAddr+":"+port+"/air/search", String.class);
        return result;
    }
}
